/*
 * Copyright © 2022-now 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springcloud.seata.storage.controller;

import cn.denvie.springcloud.seata.common.model.vo.ResultVo;
import cn.denvie.springcloud.seata.storage.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Storage控制器。
 *
 * @author Denvie
 * @date 2022/4/08
 * @since 1.0.0
 */
@RestController
@RequestMapping("/storage")
public class StorageController {
    @Autowired
    private StorageService storageService;

    /**
     * 扣减商品库存。
     * http://localhost:8630/storage/deduct?commodityCode=PRODUCT10000&count=2
     */
    @RequestMapping(path = "/deduct")
    public ResultVo<Void> deduct(String commodityCode, Integer count) {
        // 扣减商品库存
        storageService.deduct(commodityCode, count);
        return ResultVo.ok();
    }
}
